package Views;

import Controllers.KitchenCTR;
import Controllers.ItemCTR;
import Models.*;
import Views.TableModels.ItemTableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * @author Thomas og Tanja
 */
public class KitchenInfoView extends javax.swing.JFrame implements ListSelectionListener, WindowListener
{
	private Kitchen kitchen;
	private KitchenCTR controller = new KitchenCTR();
	private Item tableTopTemp = null;
	private ArrayList<Item> cupBoardsTemp = new ArrayList<Item>();
	private ArrayList<Item> drawersTemp = new ArrayList<Item>();
	private ArrayList<Item> appliancesTemp = new ArrayList<Item>();
	private ItemPicker ip = null;

	public KitchenInfoView(Kitchen kitchen)
	{
		initComponents();
		this.kitchen = kitchen;
		this.tableTopTemp = this.kitchen.getTableTop();
		this.cupBoardsTemp = this.kitchen.getCupboards();
		this.drawersTemp = this.kitchen.getDrawers();
		this.appliancesTemp = this.kitchen.getAppliances();
		getNameTF.setText(this.kitchen.getName());
		this.checkTableTop();
		getCupBoardsTable.setModel(new ItemTableModel(this.cupBoardsTemp));
		getCupBoardsTable.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e){
				if (e.getClickCount() == 2)
				{
					if(getCupBoardsTable.getSelectedRowCount() == 1)
					{
						int chosenId = Integer.parseInt(getCupBoardsTable.getValueAt(getCupBoardsTable.getSelectedRow(), 0).toString());
						ItemCTR itemController = new ItemCTR();
						new ItemInfoView(itemController.getItem(chosenId)).setVisible(true);
					}
				}
			}
		 });
		getDrawersTable.setModel(new ItemTableModel(this.drawersTemp));
		getDrawersTable.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e){
				if (e.getClickCount() == 2)
				{
					if(getDrawersTable.getSelectedRowCount() == 1)
					{
						int chosenId = Integer.parseInt(getDrawersTable.getValueAt(getDrawersTable.getSelectedRow(), 0).toString());
						ItemCTR itemController = new ItemCTR();
						new ItemInfoView(itemController.getItem(chosenId)).setVisible(true);
					}
				}
			}
		 });
		getAppliancesTable.setModel(new ItemTableModel(this.appliancesTemp));
		getAppliancesTable.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e){
				if (e.getClickCount() == 2)
				{
					if(getAppliancesTable.getSelectedRowCount() == 1)
					{
						int chosenId = Integer.parseInt(getAppliancesTable.getValueAt(getAppliancesTable.getSelectedRow(), 0).toString());
						ItemCTR itemController = new ItemCTR();
						new ItemInfoView(itemController.getItem(chosenId)).setVisible(true);
					}
				}
			}
		 });
		getPriceSP.setValue(this.kitchen.getPrice());
	}

	private void checkTableTop()
	{
		if(this.tableTopTemp != null)
		{
			getTableTF.setText(this.tableTopTemp.getName());
			removeTableButton.setEnabled(true);
			showTableButton.setEnabled(true);
		}
		else
		{
			getTableTF.setText("");
			removeTableButton.setEnabled(false);
			showTableButton.setEnabled(false);
		}
	}

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        getDescription = new javax.swing.JLabel();
        activatedCB = new javax.swing.JCheckBox();
        getNameLabel = new javax.swing.JLabel();
        getNameTF = new javax.swing.JTextField();
        getTableLabel = new javax.swing.JLabel();
        getTableTF = new javax.swing.JTextField();
        addTableButton = new javax.swing.JButton();
        removeTableButton = new javax.swing.JButton();
        showTableButton = new javax.swing.JButton();
        getCupBoardsLabel = new javax.swing.JLabel();
        cupBoardsScrollPane = new javax.swing.JScrollPane();
        getCupBoardsTable = new javax.swing.JTable();
        addCupBoardsButton = new javax.swing.JButton();
        removeCupBoardsButton = new javax.swing.JButton();
        getDrawersLabel = new javax.swing.JLabel();
        getDrawersScrollPanel = new javax.swing.JScrollPane();
        getDrawersTable = new javax.swing.JTable();
        addDrawersButton = new javax.swing.JButton();
        removeDrawersButton = new javax.swing.JButton();
        getAppliancesLabel = new javax.swing.JLabel();
        getAppliancesScrollPanel = new javax.swing.JScrollPane();
        getAppliancesTable = new javax.swing.JTable();
        addAppliancesButton = new javax.swing.JButton();
        removeAppliancesButton = new javax.swing.JButton();
        getPriceLabel = new javax.swing.JLabel();
        getPriceSP = new javax.swing.JSpinner();
        getPriceKrLabel = new javax.swing.JLabel();
        editButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Køkkeninformation");

        getDescription.setText("Her ses information om det valgte køkken");

        activatedCB.setText("Aktiveret");
        activatedCB.setEnabled(false);

        getNameLabel.setText("Navn:");

        getNameTF.setEnabled(false);

        getTableLabel.setText("Bordplade:");

        getTableTF.setEnabled(false);

        addTableButton.setText("Tilføj");
        addTableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTableButtonActionPerformed(evt);
            }
        });

        removeTableButton.setText("Fjern");
        removeTableButton.setEnabled(false);
        removeTableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeTableButtonActionPerformed(evt);
            }
        });

        showTableButton.setText("Info");
        showTableButton.setEnabled(false);
        showTableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showTableButtonActionPerformed(evt);
            }
        });

        getCupBoardsLabel.setText("Skabe:");

        getCupBoardsTable.setModel(new ItemTableModel(this.cupBoardsTemp));
        cupBoardsScrollPane.setViewportView(getCupBoardsTable);

        addCupBoardsButton.setText("Tilføj");
        addCupBoardsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCupBoardsButtonActionPerformed(evt);
            }
        });

        removeCupBoardsButton.setText("Fjern");
        removeCupBoardsButton.setEnabled(false);
        removeCupBoardsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeCupBoardsButtonActionPerformed(evt);
            }
        });

        getDrawersLabel.setText("Skuffer:");

        getDrawersTable.setModel(new ItemTableModel(this.drawersTemp));
        getDrawersScrollPanel.setViewportView(getDrawersTable);

        addDrawersButton.setText("Tilføj");
        addDrawersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDrawersButtonActionPerformed(evt);
            }
        });

        removeDrawersButton.setText("Fjern");
        removeDrawersButton.setEnabled(false);
        removeDrawersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDrawersButtonActionPerformed(evt);
            }
        });

        getAppliancesLabel.setText("Tilbehør:");

        getAppliancesTable.setModel(new ItemTableModel(this.appliancesTemp));
        getAppliancesScrollPanel.setViewportView(getAppliancesTable);

        addAppliancesButton.setText("Tilføj");
        addAppliancesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAppliancesButtonActionPerformed(evt);
            }
        });

        removeAppliancesButton.setText("Fjern");
        removeAppliancesButton.setEnabled(false);
        removeAppliancesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeAppliancesButtonActionPerformed(evt);
            }
        });

        getPriceLabel.setText("Pris:");

        getPriceSP.setEnabled(false);

        getPriceKrLabel.setText("kr.");

        editButton.setText("Rediger");
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });

        removeButton.setText("Slet");
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });

        closeButton.setText("Luk");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(getCupBoardsLabel)
                            .add(getDrawersLabel)
                            .add(getAppliancesLabel)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(getAppliancesScrollPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                                    .add(layout.createSequentialGroup()
                                        .add(getPriceLabel)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(getPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(getPriceKrLabel)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(addAppliancesButton)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(closeButton)
                                        .add(removeAppliancesButton))))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                        .add(getDescription)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 42, Short.MAX_VALUE)
                                        .add(activatedCB))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, cupBoardsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                                    .add(getDrawersScrollPanel, 0, 0, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(removeDrawersButton)
                                        .add(addDrawersButton))
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(removeCupBoardsButton)
                                        .add(addCupBoardsButton))))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(getTableLabel)
                                    .add(getNameLabel))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(getNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(layout.createSequentialGroup()
                                        .add(getTableTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(addTableButton)
                                        .add(6, 6, 6)
                                        .add(removeTableButton)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(showTableButton)))
                                .add(29, 29, 29)))
                        .add(20, 20, 20))
                    .add(layout.createSequentialGroup()
                        .add(editButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeButton))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getDescription)
                    .add(activatedCB))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getNameLabel)
                    .add(getNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getTableLabel)
                    .add(getTableTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addTableButton)
                    .add(removeTableButton)
                    .add(showTableButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(getCupBoardsLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(addCupBoardsButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeCupBoardsButton))
                    .add(cupBoardsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(getDrawersLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(getDrawersScrollPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(addDrawersButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeDrawersButton)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(getAppliancesLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(addAppliancesButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeAppliancesButton))
                    .add(getAppliancesScrollPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(getPriceLabel)
                    .add(getPriceSP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(getPriceKrLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(editButton)
                    .add(removeButton)
                    .add(closeButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void addCupBoardsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCupBoardsButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.cupBoards);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addCupBoardsButtonActionPerformed

	private void removeCupBoardsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeCupBoardsButtonActionPerformed
		int chosenId = Integer.parseInt(getCupBoardsTable.getValueAt(getCupBoardsTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.cupBoardsTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeCupBoardsButtonActionPerformed

	private void addDrawersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDrawersButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.drawers);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addDrawersButtonActionPerformed

	private void removeDrawersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDrawersButtonActionPerformed
		int chosenId = Integer.parseInt(getDrawersTable.getValueAt(getDrawersTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.drawersTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeDrawersButtonActionPerformed

	private void addAppliancesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAppliancesButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.appliances);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addAppliancesButtonActionPerformed

	private void removeAppliancesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAppliancesButtonActionPerformed
		int chosenId = Integer.parseInt(getAppliancesTable.getValueAt(getAppliancesTable.getSelectedRow(), 0).toString());
		ItemCTR stockController = new ItemCTR();
		this.appliancesTemp.remove(stockController.getItem(chosenId));
	}//GEN-LAST:event_removeAppliancesButtonActionPerformed

	private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
		if(editButton.getText().equals("Rediger")) {
			getNameTF.setEnabled(true);
			addTableButton.setEnabled(true);
			if(this.tableTopTemp != null)
			{
				removeTableButton.setEnabled(true);
				showTableButton.setEnabled(true);
			}
			addCupBoardsButton.setEnabled(true);
			addDrawersButton.setEnabled(true);
			addAppliancesButton.setEnabled(true);
			getPriceSP.setEnabled(true);
			editButton.setText("Gem");
			closeButton.setText("Annuller");
		}
		else if(editButton.getText().equals("Gem"))
		{
			this.kitchen.setName(getNameTF.getText());
			this.kitchen.setTableTop(tableTopTemp);
			this.kitchen.setCupboards(cupBoardsTemp);
			this.kitchen.setDrawers(drawersTemp);
			this.kitchen.setAppliances(appliancesTemp);
			this.kitchen.setPrice(Double.parseDouble(getPriceSP.getValue().toString()));
			editButton.setText("Rediger");
			closeButton.setText("Luk");
		}
	}//GEN-LAST:event_editButtonActionPerformed

	private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
		int choice = JOptionPane.showConfirmDialog(this, "Er du sikker på at du vil slette "+kitchen.getName()+"?", "Bekræftelse af sletning", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		if(choice == 0)
		{
			this.controller.removeKitchen(kitchen);
			this.dispose();
		}
	}//GEN-LAST:event_removeButtonActionPerformed

	private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
		this.dispose();
	}//GEN-LAST:event_closeButtonActionPerformed

	private void showTableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showTableButtonActionPerformed
		new ItemInfoView(this.tableTopTemp).setVisible(true);
	}//GEN-LAST:event_showTableButtonActionPerformed

	private void removeTableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTableButtonActionPerformed
		this.tableTopTemp = null;
		checkTableTop();
	}//GEN-LAST:event_removeTableButtonActionPerformed

	private void addTableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTableButtonActionPerformed
		ip = new ItemPicker(KitchenPartType.tableTop);
		ip.addWindowListener(this);
		ip.setVisible(true);
	}//GEN-LAST:event_addTableButtonActionPerformed

	public void valueChanged(ListSelectionEvent e)
	{
		JTable table = (JTable)e.getSource();
		if(table.equals(getCupBoardsTable))
		{
			switch(table.getSelectedRowCount())
			{
				case 1:
					removeCupBoardsButton.setEnabled(true);
					break;
				default:
					removeCupBoardsButton.setEnabled(false);
			}
		}
		if(table.equals(getDrawersTable))
		{
			switch(table.getSelectedRowCount())
			{
				case 1:
					removeDrawersButton.setEnabled(true);
					break;
				default:
					removeDrawersButton.setEnabled(false);
			}
		}
		if(table.equals(getAppliancesTable))
		{
			switch(table.getSelectedRowCount())
			{
				case 1:
					removeAppliancesButton.setEnabled(true);
					break;
				default:
					removeAppliancesButton.setEnabled(false);
			}
		}
	}

	public void windowClosing(WindowEvent e)
	{
		if(ip != null)
		{
			KitchenPartType partType = ip.getPartType();
			if(partType.equals(KitchenPartType.tableTop))
			{
				this.tableTopTemp = ip.getChosenItem();
			}
			else if(partType.equals(KitchenPartType.cupBoards))
			{
				this.cupBoardsTemp.add(ip.getChosenItem());
			}
			else if(partType.equals(KitchenPartType.drawers))
			{
				this.drawersTemp.add(ip.getChosenItem());
			}
			else if(partType.equals(KitchenPartType.appliances))
			{
				this.appliancesTemp.add(ip.getChosenItem());
			}
		}
	}

	public void windowOpened(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowActivated(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox activatedCB;
    private javax.swing.JButton addAppliancesButton;
    private javax.swing.JButton addCupBoardsButton;
    private javax.swing.JButton addDrawersButton;
    private javax.swing.JButton addTableButton;
    private javax.swing.JButton closeButton;
    private javax.swing.JScrollPane cupBoardsScrollPane;
    private javax.swing.JButton editButton;
    private javax.swing.JLabel getAppliancesLabel;
    private javax.swing.JScrollPane getAppliancesScrollPanel;
    private javax.swing.JTable getAppliancesTable;
    private javax.swing.JLabel getCupBoardsLabel;
    private javax.swing.JTable getCupBoardsTable;
    private javax.swing.JLabel getDescription;
    private javax.swing.JLabel getDrawersLabel;
    private javax.swing.JScrollPane getDrawersScrollPanel;
    private javax.swing.JTable getDrawersTable;
    private javax.swing.JLabel getNameLabel;
    private javax.swing.JTextField getNameTF;
    private javax.swing.JLabel getPriceKrLabel;
    private javax.swing.JLabel getPriceLabel;
    private javax.swing.JSpinner getPriceSP;
    private javax.swing.JLabel getTableLabel;
    private javax.swing.JTextField getTableTF;
    private javax.swing.JButton removeAppliancesButton;
    private javax.swing.JButton removeButton;
    private javax.swing.JButton removeCupBoardsButton;
    private javax.swing.JButton removeDrawersButton;
    private javax.swing.JButton removeTableButton;
    private javax.swing.JButton showTableButton;
    // End of variables declaration//GEN-END:variables
}
